
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 05/07/2013 23:07:47
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class Contact
    /// </summary>
    [Serializable]
    public partial class Contact : _DomainLayer_Base
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_InnoAppUser.
        /// </summary>
        /// <value>The FK_InnoAppUser.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual System.Guid FK_InnoAppUser
        {
            get { return _fK_InnoAppUser; }
            set
            {
                if (_fK_InnoAppUser != value)
                {
                    if (InnoAppUser != null && InnoAppUser.Id != value)
                    {
                        InnoAppUser = null;
                    }
                    _fK_InnoAppUser = value;
                }
            }
        }
        private System.Guid _fK_InnoAppUser;
    	
        /// <summary>
        /// Gets or sets FK_Genre.
        /// </summary>
        /// <value>The FK_Genre.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual int FK_Genre
        {
            get { return _fK_Genre; }
            set
            {
                if (_fK_Genre != value)
                {
                    if (Genre != null && Genre.Id != value)
                    {
                        Genre = null;
                    }
                    _fK_Genre = value;
                }
            }
        }
        private int _fK_Genre;
    	
        /// <summary>
        /// Gets or sets FirstName.
        /// </summary>
        /// <value>The FirstName.</value>
        public virtual string FirstName
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets LastName.
        /// </summary>
        /// <value>The LastName.</value>
        public virtual string LastName
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties
    
        /// <summary>
        /// Link Contact to all Contact__AdressType__ContactAddress
        /// </summary>
        public virtual ICollection<Contact__AdressType__ContactAddress> Contact__AdressType__ContactAddress
        {
            get
            {
                if (_contact__AdressType__ContactAddress == null)
                {
                    var newCollection = new FixupCollection<Contact__AdressType__ContactAddress>();
                    newCollection.CollectionChanged += FixupContact__AdressType__ContactAddress;
                    _contact__AdressType__ContactAddress = newCollection;
                }
                return _contact__AdressType__ContactAddress;
            }
            set
            {
                if (!ReferenceEquals(_contact__AdressType__ContactAddress, value))
                {
                    var previousValue = _contact__AdressType__ContactAddress as FixupCollection<Contact__AdressType__ContactAddress>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupContact__AdressType__ContactAddress;
                    }
                    _contact__AdressType__ContactAddress = value;
                    var newValue = value as FixupCollection<Contact__AdressType__ContactAddress>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupContact__AdressType__ContactAddress;
                    }
                }
            }
        }
        private ICollection<Contact__AdressType__ContactAddress> _contact__AdressType__ContactAddress;
    
        /// <summary>
        /// Link Contact to all Contact__Competency
        /// </summary>
        public virtual ICollection<Contact__Competency> Contact__Competency
        {
            get
            {
                if (_contact__Competency == null)
                {
                    var newCollection = new FixupCollection<Contact__Competency>();
                    newCollection.CollectionChanged += FixupContact__Competency;
                    _contact__Competency = newCollection;
                }
                return _contact__Competency;
            }
            set
            {
                if (!ReferenceEquals(_contact__Competency, value))
                {
                    var previousValue = _contact__Competency as FixupCollection<Contact__Competency>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupContact__Competency;
                    }
                    _contact__Competency = value;
                    var newValue = value as FixupCollection<Contact__Competency>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupContact__Competency;
                    }
                }
            }
        }
        private ICollection<Contact__Competency> _contact__Competency;
        public virtual Genre Genre
        {
            get { return _genre; }
            set
            {
                if (!ReferenceEquals(_genre, value))
                {
                    var previousValue = _genre;
                    _genre = value;
                    FixupGenre(previousValue);
                }
            }
        }
        private Genre _genre;
        public virtual InnoAppUser InnoAppUser
        {
            get { return _innoAppUser; }
            set
            {
                if (!ReferenceEquals(_innoAppUser, value))
                {
                    var previousValue = _innoAppUser;
                    _innoAppUser = value;
                    FixupInnoAppUser(previousValue);
                }
            }
        }
        private InnoAppUser _innoAppUser;
    
        /// <summary>
        /// Link Contact to all Order
        /// </summary>
        public virtual ICollection<Order> Order
        {
            get
            {
                if (_order == null)
                {
                    var newCollection = new FixupCollection<Order>();
                    newCollection.CollectionChanged += FixupOrder;
                    _order = newCollection;
                }
                return _order;
            }
            set
            {
                if (!ReferenceEquals(_order, value))
                {
                    var previousValue = _order as FixupCollection<Order>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupOrder;
                    }
                    _order = value;
                    var newValue = value as FixupCollection<Order>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupOrder;
                    }
                }
            }
        }
        private ICollection<Order> _order;

        #endregion
        #region Association Fixup
    
        private void FixupGenre(Genre previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (Genre != null)
            {
                if (!Genre.Contact.Contains(this))
                {
                    Genre.Contact.Add(this);
                }
                if (FK_Genre != Genre.Id)
                {
                    FK_Genre = Genre.Id;
                }
            }
        }
    
        private void FixupInnoAppUser(InnoAppUser previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (InnoAppUser != null)
            {
                if (!InnoAppUser.Contact.Contains(this))
                {
                    InnoAppUser.Contact.Add(this);
                }
                if (FK_InnoAppUser != InnoAppUser.Id)
                {
                    FK_InnoAppUser = InnoAppUser.Id;
                }
            }
        }
    
        private void FixupContact__AdressType__ContactAddress(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Contact__AdressType__ContactAddress item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Contact__AdressType__ContactAddress item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupContact__Competency(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Contact__Competency item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Contact__Competency item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupOrder(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Order item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Order item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }

        #endregion
    }
}
